/*
 * utils.c
 *
 *  Created on: Jan 7, 2012
 *      Author: ian
 */

#include <stdio.h>
#include "utils.h"

void byte2hex( uint8_t by, char* pCh )
{
	const char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
	pCh[0] = hexval[ (by >> 4) & 0x0f ];
	pCh[1] = hexval[ by & 0x0f ];
	pCh[2] = 0x00;
}

void int2str( unsigned int val, unsigned char len, char *p)
{
	char *tp;
	unsigned char i;

	tp = p;
	for( i = 0; i < len; i++ ) *(tp++) = ' ';	//start with blank string of specified length
	*(tp--) = 0;								//terminated & now points at 1's

	if( val == 0 ) {
		*tp = '0';
	}
	else {
		while( val ) {
			i = val % 10;
			val = val / 10;
			*(tp--) = i + '0';
		}
	}
}
